home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50b Issue 142 (CD142b) (August 1998).iso / essent / FIXES / CSeries.exe / issue99 / CPROG8.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-05  |  1.6 KB  |  96 lines

  1. /* CPROG8.CPP - the bare bones of a menu system
  2.  
  3. THIS VERSION OF THE FILE IS NOT COMMENTED SO THAT YOU CAN CLEARLY SEE
  4. HOW THE PROGRAM IS STRUCTURED. PROGRAM FILE CPROG8-A.CPP IS EXACTLY
  5. THE SAME CODE WITH LOTS OF EXPLANATORY TEXT
  6.  
  7. */
  8.  
  9.  
  10. #include <stdio.h>
  11. #include <conio.h>
  12. #include <stdlib.h>
  13. #include <dos.h>
  14. #include <ctype.h>
  15.  
  16. #define BEEP sound(300); delay(500); nosound();
  17.  
  18. ////////////////////////////////////
  19. void pause(void)
  20. {
  21.     printf("\nPress a key...\n");
  22.     while( kbhit() == 0 )
  23.         ;
  24.     (void)getch();
  25. }
  26.  
  27. ////////////////////////////////////
  28. void showmenu(void)
  29. {
  30.     clrscr();
  31.     printf("Press...\n");
  32.     printf("1 ... for menu item 1\n");
  33.     printf("2 ... for menu item 2\n");
  34.     printf("3 ... for menu item 3\n");
  35.     printf("\nQ ... to quit\n");
  36. }
  37.  
  38. ////////////////////////////////////
  39. void action1(void)
  40. {
  41.     clrscr();
  42.     printf("The program code for menu item 1\n");
  43.     pause();
  44. }
  45.  
  46. ////////////////////////////////////
  47. void action2(void)
  48. {
  49.     clrscr();
  50.     printf("The program code for menu item 2\n");
  51.     pause();
  52.  
  53. }
  54.  
  55. ////////////////////////////////////
  56. void action3(void)
  57. {
  58.     clrscr();
  59.     printf("The program code for menu item 3\n");
  60.     pause();
  61.  
  62. }
  63.  
  64. ////////////////////////////////////
  65. ////////////////////////////////////
  66. int main(void)
  67. {
  68. int kpress;
  69.  
  70.     while( 1 )
  71.         {
  72.         showmenu();
  73.         kpress=getch();
  74.         kpress=toupper(kpress);
  75.         switch( kpress )
  76.             {
  77.             case '1':
  78.                 action1();
  79.                 break;
  80.  
  81.             case '2':
  82.                 action2();
  83.                 break;
  84.  
  85.             case '3':
  86.                 action3();
  87.                 break;
  88.  
  89.             case 'Q':
  90.                 exit(0);
  91.  
  92.             default:
  93.                 BEEP
  94.             }
  95.         }
  96. }